//方法1
var reverse1 = function (x) {
    //符号判断
    const isSign = Math.sign(x) === -1;
    console.log(isSign);
    //字符串--数组--反转--字符串
    const a = (Math.abs(x) + '').split('').reverse().join('');
    //定义最大最小范围
    const maxVal = 2**31-1;
    const minVal = (-2)**31;
    const reverseX = isSign?-a:a;
    if (reverseX >= maxVal || reverseX <= minVal){
        return 0;
    }
    return reverseX;
};

//方法2
var reverse2 = function(x){
  var overflow = function(x) {
      return x >= 2**31-1 || x<= (-2)**31?0:x;
  };
  x = overflow(x);
  let isNegative = x < 0;
  if (isNegative){
      x = -x;
  }
  let a = 0;
  while (x > 9){
      a = a * 10 + x % 10 * 10;
      x = parseInt(x / 10);
  }
  a += x;
  return isNegative? overflow(-a) : overflow(a);
};


console.log(reverse2(123456789));